let express = require('express');
let router = express.Router();
let multer = require("multer");
let path = require('path');

let storage = multer.diskStorage({
  // 上传的路径
  destination: function (req, res, cb) {
    cb(null, path.join(__dirname, '../uploads'));
  },
  filename: function (req, file, cb) {
    console.log(file);//fieldname 文件名字 大小
    cb(null, file.fieldname + req.body.filename + '-' + file.originalname);
}
});


let upload = multer({storage});//上传的目录

router.post('/', upload.single("photos"), function (req, res, next) {

  // req.file
  res.json({
    img: 'http://localhost:4000/' + req.file.filename

  })

});


module.exports = router;
